package com.codedancer.campus.manager.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.codedancer.campus.manager.service.ICircleExamineRecordService;
import com.codedancer.campus.manager.service.vo.circle.CircleExamineRecordPageVo;
import com.codedancer.campus.mapper.AdminMapper;
import com.codedancer.campus.mapper.CircleExamineRecordMapper;
import com.codedancer.campus.po.Admin;
import com.codedancer.campus.po.CircleExamineRecord;
import java.util.List;
import java.util.stream.Collectors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional(rollbackFor = Exception.class)
public class CircleExamineRecordServiceImpl implements ICircleExamineRecordService {

    @Autowired
    private CircleExamineRecordMapper circleExamineRecordMapper;
    @Autowired
    private AdminMapper adminMapper;

    /**
     * 查询圈子审核记录
     *
     * @param circleUuid
     * @return
     */
    @Override
    public List<CircleExamineRecordPageVo> list(String circleUuid) {
        List<CircleExamineRecord> circleExamineRecords = circleExamineRecordMapper.list(circleUuid);
        List<CircleExamineRecordPageVo> circleExamineRecordPageVos;
        circleExamineRecordPageVos = circleExamineRecords.stream().map(circleExamineRecord -> {
            CircleExamineRecordPageVo circleExamineRecordPageVo = BeanUtil
                .copyProperties(circleExamineRecord, CircleExamineRecordPageVo.class);
            Admin admin = adminMapper.selectById(circleExamineRecord.getExamineAdminUuid());
            circleExamineRecordPageVo.setExamineAdminName(admin.getLoginName());
            return circleExamineRecordPageVo;
        }).collect(Collectors.toList());
        return circleExamineRecordPageVos;
    }
}
